package com.easyedu.dean.controller;

import com.easyedu.core.entity.po.Teacher;
import com.easyedu.core.util.R;
import com.easyedu.dean.entity.dto.request.ReqTeacher;
import com.easyedu.core.entity.query.TeacherQuery;
import com.easyedu.dean.service.TeacherService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @author lmr</ br>
 * 教师管理
 **/
@Validated
@RestController
@RequestMapping("/dean")
public class TeacherController {

    private final TeacherService teacherService;

    public TeacherController(TeacherService teacherService) {
        this.teacherService = teacherService;
    }

    /**
     * 功能描述: 获取教室列表
     *
     * @param teacherNumber  1 教师编号
     * @param name           2 教师姓名
     * @param instituteName  3 所属学院
     * @param departmentName 4 所属专业
     * @return : com.easyedu.api.util.R
     **/
    @GetMapping("/teacher/list")
    public R getTeacher(@RequestParam(defaultValue = "0") long teacherNumber,
                        @RequestParam(required = false) String name,
                        @RequestParam(required = false) String instituteName,
                        @RequestParam(required = false) String departmentName) {
        TeacherQuery teacherQuery = new TeacherQuery();
        teacherQuery.setTeacherNumber(teacherNumber);
        teacherQuery.setName(name);
        teacherQuery.setInstituteName(instituteName);
        teacherQuery.setDepartmentName(departmentName);
        List<Teacher> teacherList = teacherService.getTeacherList(teacherQuery);
        return R.ok().data(teacherList);
    }

    /**
     * 功能描述: 新增教师
     *
     * @param teachers 1 教师信息集 Persistant Object
     * @return : com.easyedu.api.util.R
     **/
    @PostMapping("/teacher")
    public R createTeachers(@RequestBody @Valid List<ReqTeacher> teachers) {
        return R.ok().message(teacherService.createTeachers(teachers));
    }

    /**
     * 功能描述:删除教师
     *
     * @param teacherId 1 教师id
     * @return : com.easyedu.api.util.R
     **/
    @DeleteMapping("/teacher")
    public R deleteTeacher(@RequestParam Long teacherId) {
        teacherService.deleteTeacher(teacherId);
        return R.ok().message("删除教师成功");
    }

    /**
     * 更新教师信息
     * @param reqTeacher
     * @return
     */
    @PutMapping("/teacher")
    public R updateTeachers(@RequestBody @Valid ReqTeacher reqTeacher) {
        teacherService.updateTeacher(reqTeacher);
        return R.ok().message("更新教师成功");
    }
}
